require(['./config'], () => {
    require(['header', 'footer', 'cookie'], (header) => {
      class Login {
        constructor () {
          this.login()
        }
        login(){
          $('#sub').on('click',function(){
            var phone = $('#phone').val()
            var loginpwd = $('#loginpwd').val()
            let user = localStorage.getItem('user')
            if(user){
              user = JSON.parse(user)
              const isExist = user.some(name => {
                return name.phone === phone && name.loginpwd === loginpwd
              })
              console.log(isExist)
              if(isExist){
                $('.register b').show()
                setTimeout(function(){
                  $('.register b').hide()
                  $.cookie('name', phone, { expires: 3, path: '/' })
                  header.userName()
                  location.href = '/index.html'
                },1000)
              }else{
                $('#warning span').html('账号或者密码错误')
                $('#warning').show()
                setTimeout(function(){
                  $('#phone').val('')
                  $('#loginpwd').val('')
                  $('#warning').hide()
                },1000)
              }
            }
            else{
              $('#warning span').html('先注册哦 , 亲')
              $('#warning').show()
              setTimeout(function(){
                $('#phone').val('')
                $('#loginpwd').val('')
                $('#warning').hide()
              },1000)
            }
          })
        }
      }
      new Login()
    })
})